@{
    ViewData["Title"] = "Users";
    var nextPage = ViewBag.pageNum + 1 > ViewBag.pageTotal ? ViewBag.pageTotal : ViewBag.pageNum + 1;
    var prePage = ViewBag.pageNum - 1 < 1 ? 1 : ViewBag.pageNum - 1;
}
<div>
    <h3>@ViewData["Title"]</h3>
</div>
<div>
    <div>
        <button style="margin-left: 90%;margin-bottom:20px;" id="add" type="button" class="btn btn-primary">Add User</button>
    </div>
    <table class="table">
        <thead>
            <tr>
            <th scope="col">Id</th>
            <th scope="col">Name</th>
            <th scope="col">Account</th>
            <th scope="col">Password</th>
            <th scope="col">Operate</th>
            </tr>
        </thead>
        <tbody>
            @foreach(var user in ViewBag.Users)
            {
                <tr>
                    <th scope="row">@user.id</th>
                    <td>@user.name</td>
                    <td>@user.account</td>
                    <td>@user.password</td>
                    <td>
                        <a onclick="editUserClick(@user.id)" href="javascript:void(0);" class="badge badge-primary">Edit</a>
                        <a onclick="deleteUserClick(@user.id)" href="javascript:void(0);" class="badge badge-danger">Delete</a>
                    </td>
                </tr>
            }
        </tbody>
    </table>
    <div>
    @if(ViewBag.pageTotal > 0) {        
    <ul aria-label="Page navigation example" style="margin-left: -40px;">
        @if(ViewBag.pageTotal == 1) {
        <ul style="float: right;" class="pagination">
            <li class="page-item active"><a class="page-link" href="/user/index?pageNum=1">1 <span class="sr-only">(current)</span></a></li>
        </ul>
        } else {
        <ul style="float: right;" class="pagination">
            @if(ViewBag.pageNum > 1) {
                <a class="page-link" href="/user/index?pageNum=@prePage" aria-label="Previous">
                    <span aria-hidden="true">&laquo;</span>
                    <span class="sr-only">Previous</span>
                </a>
            }
            @{
                for(int i = 1; i <= ViewBag.pageTotal; i++) {
                    @if(i == ViewBag.pageNum) {
                        <li class="page-item active"><a class="page-link" href="/user/index?pageNum=@i">
                        @i
                        <span class="sr-only">(current)</span>
                    </a></li>
                    } else {
                        <li class="page-item"><a class="page-link" href="/user/index?pageNum=@i">
                        @i
                        </a></li>
                    }
                    
                }
            }
            @if(ViewBag.pageNum < ViewBag.pageTotal) {
                <li class="page-item">
                    <a class="page-link" href="/user/index?pageNum=@nextPage" aria-label="Next">
                        <span aria-hidden="true">&raquo;</span>
                        <span class="sr-only">Next</span>
                    </a>
                </li>
            }
        </ul>
        }
        <p class="font-weight-light" style="font-size: 14px;">共 @ViewBag.pageTotal 页，共 @ViewBag.total 项 @ViewBag.test</p>
    </ul>
    }
    </div>
</div>
@section Scripts 
{
    <script src="~/js/user/index.js"></script> 
}
